package de.karlNet.sambamanager.ldapController.commands.attributeBuilder;

import java.util.ArrayList;
import java.util.List;

import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;

import org.springframework.stereotype.Component;

import de.karlNet.sambamanager.ldapModel.LdapGroup;

@Component
public class GroupAttributeBuilder {
	public BasicAttributes buildGroupAttributes(LdapGroup ldapGroup) {
		BasicAttributes basicAttributes = new BasicAttributes();
		for (BasicAttribute attribute : this.buildGroupAttributeList(ldapGroup)) {
			basicAttributes.put(attribute);
		}
		return basicAttributes;
	}

	public List<BasicAttribute> buildGroupAttributeList(LdapGroup ldapGroup) {
		ArrayList<BasicAttribute> attributes = new ArrayList<BasicAttribute>();
		BasicAttribute samaccountname = new BasicAttribute("samaccountname",
				ldapGroup.getCn());
		attributes.add(samaccountname);

		BasicAttribute groupName = new BasicAttribute("cn", ldapGroup.getCn());
		attributes.add(groupName);
		BasicAttribute objectClass = new BasicAttribute("objectclass");
		objectClass.add("group");
		attributes.add(objectClass);
		return attributes;
	}
}
